|
|
|
|
|
|
|
To see that this transformation matrix works, multiply a generic point (x, y, z) by the generic translation matrix. |
|
|
|
|
|
|
|
|
The result, (x + Tx, y + Ty, z + Tz), is the correct translation of the point (x, y, z). |
|
|
|
|
|
|
|
|
To make translation easy in Visual Basic, you can write a routine that initializes the entries in a transformation matrix to represent translation. This routine calls subroutine m3Identity to initialize the matrix to the identity matrix. It then sets the three entries needed for translation. |
|
|
|
 |
|
|
|
|
' Create a 3-D transformation matrix for
' translation by Tx, Ty, and Tz. Public Sub m3Translate(M() As Single, _
Tx As Single, Ty As Single, Tz As Single)
Dim i As Integer
m3Identity M()
M(4, 1) = Tx
M(4, 2) = Ty
M(4, 3) = Tz
End Sub |
|
|
|
|
|
|
|
|
Three-dimensional scaling also generalizes easily from two dimensions. To scale a point by a factor of Sx in the X direction, Sy in the Y direction, and Sz in the Z direction, multiply the point by the matrix: |
|
|
|
|
|
|
|
|
You can verify that this matrix properly represents scaling by multiplying it by the point (x, y, z). |
|
|
|
|
|
|
|
|
The following code shows a routine that initializes scaling transformation matrices. |
|
|
|
|
|